package com.lz;

import static java.lang.System.out;

/**
 * @description
 *
 * @date 2021-11-10 15:50
 *
 * @author Lizhong
 */
public class SynchrozieDemo {
    public static void main(String[] args) throws InterruptedException {
        Object a = new Object();
        int i = a.hashCode();
        System.out.println(Integer.toHexString(i));
        Thread thread2 = new Thread(() -> {
            synchronized (a) {
                out.println(Long.toHexString(Thread.currentThread().getId()));
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            try {
                Thread.sleep(1000000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        });
        thread2.start();

        Thread thread1 = new Thread(() -> {
            synchronized (a) {

                out.println(Long.toHexString(Thread.currentThread().getId()));
            }
            try {
                Thread.sleep(1000000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        });
        thread1.start();

        Thread thread = new Thread(() -> {
            synchronized (a) {
                out.println(Long.toHexString(Thread.currentThread().getId()));
            }
            try {
                Thread.sleep(1000000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        });
        thread.start();

        Thread.sleep(1000000);


    }
}
